<?php

function getUserHistory($userId){
    global $db;
    
    $query = 'SELECT * FROM RESERVATIONS WHERE IDUser ='. $userId ;
    $result = $db->query($query); 
    
    $reservations = array();
    
    if($result):
        while ($row = $result->fetch_assoc()):
            array_push($reservations, array( "reservationID" => $row['ID'], "Check-IN" => $row['DateIn'], 
						"Check-Out" => $row['DateOut'], "Price" => $row['PriceSummary'], "Days" => $row['Days'], 
						"IDUser" => $row['IDUser'], "IDRoom"=> $row['IDRoom']));
        endwhile;
    endif;
    
    return $reservations;
}
function getUserHistoryTest(){		// for testing
    global $db;
    
    $query = 'SELECT * FROM RESERVATIONS ';
    $result = $db->query($query); 
    
    $reservations = array();
    
    if($result):
        while ($row = $result->fetch_assoc()):
            array_push($reservations, array( "reservationID" => $row['ID'], "Check-IN" => $row['DateIn'], 
						"Check-Out" => $row['DateOut'], "Price" => $row['PriceSummary'], "Days" => $row['Days'], 
						"IDUser" => $row['IDUser'], "IDRoom"=> $row['IDRoom']));
        endwhile;
    endif;
    
    return $reservations;
}
function getRoomTypeFromRoomID ($id){
    global $db;
    
    $query = 'SELECT Details FROM ROOM_TYPES WHERE ID ='. $id ;
    $result = $db->query($query); 


    
    if($result){
       $row = $result->fetch_assoc();
           $roomType = $row['Details'];
	}

    return $roomType;

}
function getHotelNameFromRoomID ($id){
    global $db;
    
    $query = 'SELECT Name FROM `HOTELS` WHERE ID=(SELECT Hotel FROM ROOM_TYPES WHERE ID ='.$id.')';
    $result = $db->query($query); 
  
    if($result){
       $row = $result->fetch_assoc();
           $HotelName = $row['Name'];
	}

    return $HotelName;

}



?>